package com.hexiang.web;

import java.util.List;

import com.hexiang.domain.City;
import com.hexiang.service.CityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping(value = "/city")
public class CityController {

    @Autowired
    private CityService cityService;

    @GetMapping(value = "/{id}")
    public City findCityById(@PathVariable("id") Long id) {
        return cityService.findCityById(id).orElse(new City());
    }

    @GetMapping()
    public List<City> findAllCity() {
        return cityService.findAllCity();
    }

    @PostMapping()
    public City saveCity(@RequestBody City city) {
        return cityService.save(city);
    }

    @PutMapping()
    public City modifyCity(@RequestBody City city) {
        return cityService.modifyCity(city);
    }

    @DeleteMapping(value = "/{id}")
    public Long deleteCity(@PathVariable("id") Long id) {
        return cityService.deleteCity(id);
    }
}
